﻿using Architecture.Repository;
using Architeture.Domain;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.ZhuBoLin.Application.Command.RoleCommand.Slaughter;
using RBAC.ZhuBoLin.Dtos;

namespace RBAC.ZhuBoLin.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class SlaughterController : ControllerBase
    {
        protected readonly IMediator mediator;

        public SlaughterController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 屠宰添加
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ApiResult<int>> SlaughterAdd(SlaughterCreateCommand cd)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await mediator.Send(cd);
            }
            catch (Exception ex)
            {
                result.Code = 1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 屠宰显示
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ApiResult<slaughterInfo>> GetSlaughter([FromQuery]SlaughSelectCommand cd)
        {
            ApiResult<slaughterInfo> result = new ApiResult<slaughterInfo>();
            try
            {
                result.Data = await mediator.Send(cd);
            }
            catch (Exception ex)
            {
                result.Code = 1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
    }
}
